package com.kawins.result;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回结果
 *
 * @author rankai
 *         createTime 2017-04-2017/4/20 14:47
 */
public class ResultTo extends HashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = -6125210369527938613L;

    // 返回结果编码
    private static final String RESULT_CODE = "code";
    // 返回结果信息
    private static final String RESULT_MESSAGE = "message";
    // 返回结果数据
    private static final String RESULT_DATA = "data";

    private static final String RESULT_PERMS = "perms";

    public ResultTo() {
        this.put(RESULT_CODE, ResultEnum.SUCCESS.getCode());
        this.put(RESULT_MESSAGE, ResultEnum.SUCCESS.getMessage());
    }

    public ResultTo(ResultEnum resultEnum) {
        this.put(RESULT_CODE, resultEnum.getCode());
        this.put(RESULT_MESSAGE, resultEnum.getMessage());
    }

    public ResultTo(ResultEnum resultEnum, String message) {
        this.put(RESULT_CODE, resultEnum.getCode());
        this.put(RESULT_MESSAGE, message);
    }

    public ResultTo(int code, String message) {
        this.put(RESULT_CODE, code);
        this.put(RESULT_MESSAGE, message);
    }

    public ResultTo setData(Object object) {
        this.put(RESULT_DATA, object);
        return this;
    }

    public ResultTo setData(String dataName, Object object) {
        this.put(dataName, object);
        return this;
    }

    public ResultTo setData(Map<String, Object> map) {
        this.putAll(map);
        return this;
    }

    public void setPerms(Object object) {
        this.put(RESULT_PERMS, object);
    }
}
